//
//  FactoryViewController.m
//  ShoppingExperience
//
//  Created by LiYinDi on 14-12-29.
//  Copyright (c) 2014年 RuiBen. All rights reserved.
//

#import "FactoryViewController.h"


@interface FactoryViewController ()
{
     NSUInteger previousSelectedIndex;
}
@end

@implementation FactoryViewController
@synthesize factoryViewControllers = _factoryViewControllers;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)viewWillAppear:(BOOL)animated
{
    [self setSelectedIndex:0];
   // [Global setHomeCustomID:4];
}
- (void)setSelectedIndex:(NSUInteger)selectedIndex
{
    if (selectedIndex<[self.factoryViewControllers count]) {
        if (previousSelectedIndex != NSNotFound)
        {
            UIViewController *previousViewController = [self.factoryViewControllers objectAtIndex:previousSelectedIndex];
            [previousViewController.view removeFromSuperview];
            [previousViewController removeFromParentViewController];
        }
        
        UIViewController *selectedViewController = [self.factoryViewControllers objectAtIndex:selectedIndex];
        [self addChildViewController:selectedViewController];
        selectedViewController.view.frame = CGRectMake(0, 0, DEFAULT_FirstLevelView_WIDTH, DEFAULT_FirstLevelView_HEIGHT);
        selectedViewController.view.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
        [self.view addSubview:selectedViewController.view];
        // remove previously selected view controller (if any)
        previousSelectedIndex=selectedIndex;
    }
    
}
- (void)setFactoryViewControllers:(NSArray *)viewControllers
{
    _factoryViewControllers = [viewControllers copy];
    previousSelectedIndex=NSNotFound;
    // create tab bar items
}
-(void)factoryDynamicCellClick:(NSUInteger)index
{
   // NSLog(@"lllllll");
    [self setSelectedIndex:1];
}
-(void)factoryDynamicDetailBackClick
{
    [self setSelectedIndex:0];
}
-(void)factoryNewProductRightCellClick
{
    [self setSelectedIndex:1];
}
-(void)factoryNewProductDetailBackClick
{
    [self setSelectedIndex:0];
}
-(void)factoryActivityCellClick:(NSString *)codeStr
{
   // NSLog(@"////////////=%d",index);
     [self setSelectedIndex:2];
}
-(void)factoryActivityDetailBackClick
{
   
     [self setSelectedIndex:0];
}
-(void)videoBtnSelected:(NSUInteger)index
{
     [self setSelectedIndex:3];
}
-(void)factoryTrainDetailBackClick
{
     [self setSelectedIndex:0];
}
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
